W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem [email protected].
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, zapraszamy na serwery Discord. Są one moderowane przez społeczność, ale członkowie zespołu technicznego też są tam aktywni.
soldiers are standing in a double-row. They have to be rearranged, so that there are no equally tall soldiers in each row - then we shall say, that the soldiers are set up properly.
A single operation consists in swapping two soldiers who occupy the same position (but in different rows). Your task is to determine the minimum number of swaps necessary to set the soldiers up properly.
There is a double-row of soldiers in the figure. Arrows indicate the swaps that rearrange the soldiers in a proper way.
Write a programme that:
In the first line of the input there is one integer , . In each of the two rows there are soldiers standing. In each of the following two lines there are positive integers separated by single spaces. In the second line there are numbers , ; denotes the height of the 'th soldier in the first line. In the third line there are numbers , ; denotes the height of the 'th soldier in the second line.
It is guaranteed that in the instances from the test data it is possible to set up soldiers properly.
In the first and only line of the standard output one integer should be written - the minimum number of swaps necessary to set up soldiers properly.
For the input data:
9 2 5 5 2 7 4 7 3 9 1 6 8 4 6 3 9 1 8
the correct result is:
3
Task author: Wojciech Rytter.